package com.zmx.patientend.adapter;

/**
 * 程序猿：胖胖祥
 * 时 间：2021/3/15  13:28
 * 功 能：
 */

import android.content.Context;

import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.zmx.patientend.R;
import com.zmx.patientend.pojo.ChildEntity;
import com.zmx.patientend.view.util.GroupEntity;

import java.util.ArrayList;

/**
 * @data on 11/25/20 2:13 PM
 * @auther armStrong
 * @describe 这是普通的分组Adapter 每一个组都有头部、尾部和子项。
 */
public class GroupedListAdapter extends GroupedRecyclerViewAdapter {
    protected ArrayList<GroupEntity> mGroups;

    public GroupedListAdapter(Context context, ArrayList<GroupEntity> groups) {
        super(context);
        mGroups = groups;
    }

    @Override
    public int getGroupCount() {
        return mGroups == null ? 0 : mGroups.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        ArrayList<ChildEntity> children = mGroups.get(groupPosition).getChildren();
        return children == null ? 0 : children.size();
    }

    public void clear(){
        mGroups.clear();
        notifyDataChanged();
    }

    public void setGroups(ArrayList<GroupEntity> groups){
        mGroups = groups;
        notifyDataChanged();
    }

    @Override
    public boolean hasHeader(int groupPosition) {
        return true;
    }

    @Override
    public boolean hasFooter(int groupPosition) {
        return true;
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return R.layout.adapter_header;
    }

    @Override
    public int getFooterLayout(int viewType) {
        return R.layout.adapter_footer;
    }

    @Override
    public int getChildLayout(int viewType) {
        return R.layout.adapter_child;
    }

    @Override
    public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) {
        GroupEntity entity = mGroups.get(groupPosition);
        holder.setText(R.id.tv_header, entity.getDate());
        holder.setText(R.id.income, "收入："+entity.getIncome());
        holder.setText(R.id.expens, "支出："+entity.getExpens());
    }

    @Override
    public void onBindFooterViewHolder(BaseViewHolder holder, int groupPosition) {
        GroupEntity entity = mGroups.get(groupPosition);
        holder.setText(R.id.tv_footer, entity.getFooter());
    }

    @Override
    public void onBindChildViewHolder(BaseViewHolder holder, int groupPosition, int childPosition) {
        ChildEntity entity = mGroups.get(groupPosition).getChildren().get(childPosition);
        holder.setText(R.id.tv_child, entity.getOrder());
        holder.setText(R.id.time, entity.getAddtime());

        if (entity.getType() == 0){
            holder.setText(R.id.money, "+"+entity.getMoney());
        }else if (entity.getType() == 1){
            holder.setText(R.id.money, "-"+entity.getMoney());
        }else if (entity.getType() == 2){
            holder.setText(R.id.money, "+"+entity.getMoney());
        }else{
            holder.setText(R.id.money, "-"+entity.getMoney());
        }


    }
}